package com.GZHU.controller.save_info;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
@RestController
public class Save_upload_info {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @RequestMapping("/save_upload_info")
    public void Save_upload_info(@RequestParam("upload_id") String upload_id,
                                 @RequestParam("model_id") String model_id,
                                 @RequestParam("producer_id") String producer_id,
                                 @RequestParam("upload_time") String upload_time,
                                 HttpServletResponse response) throws IOException {
        String str= String.format("VALUES ('%s', '%s', '%s', '%s')",upload_id,model_id,producer_id,upload_time );
        String sql="INSERT INTO `upload_info` (`upload_id`, `model_id`, `producer_id`, `upload_time`)" +str;
        try {
            jdbcTemplate.execute(sql);
            log.info("data save success!");
        }catch (Exception e){
            log.info("data save fail!");
        }
        response.sendRedirect("/data_save.html");
    }
}
